<template>
  <div class="vintage-journal">
    <div class="entries-list">
      <div
        v-for="(entry, index) in entries"
        :key="entry.id"
        class="entry-page"
        :style="{ animationDelay: `${index * 0.1}s` }"
      >
        <!-- 纸张纹理背景 -->
        <div class="paper-texture"></div>

        <!-- 装饰性边框 -->
        <div class="decorative-border">
          <div class="corner corner-tl"></div>
          <div class="corner corner-tr"></div>
          <div class="corner corner-bl"></div>
          <div class="corner corner-br"></div>
        </div>

        <!-- 日期邮戳 -->
        <div class="date-stamp">
          <div class="stamp-circle">
            <div class="stamp-top">{{ formatYear(entry.date) }}</div>
            <div class="stamp-middle">{{ formatMonthDay(entry.date) }}</div>
            <div class="stamp-bottom">{{ getWeekday(entry.date) }}</div>
          </div>
        </div>

        <!-- 天气标签 -->
        <div v-if="entry.weather" class="weather-label">
          {{ getWeatherText(entry.weather) }}
        </div>

        <!-- 心情贴纸 -->
        <div v-if="entry.mood" class="mood-sticker" :class="`mood-${entry.mood}`">
          {{ getMoodText(entry.mood) }}
        </div>

        <!-- 内容区域 -->
        <div class="content-area">
          <!-- 标题 -->
          <h3 v-if="entry.title" class="entry-title">{{ entry.title }}</h3>

          <!-- 手写风格的内容 -->
          <div class="entry-content">
            <p class="handwriting">{{ entry.content }}</p>
          </div>

          <!-- 标签（复古标签风格） -->
          <div v-if="entry.tags && entry.tags.length" class="vintage-tags">
            <span v-for="tag in entry.tags" :key="tag" class="vintage-tag">
              {{ tag }}
            </span>
          </div>
        </div>

        <!-- 底部时间戳 -->
        <div class="footer-time">
          记于 {{ formatFullTime(entry.createdAt) }}
        </div>

        <!-- 装饰性图案 -->
        <div class="decoration-flower">✿</div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import type { JournalEntry } from '../types'

interface Props {
  entries: JournalEntry[]
}

defineProps<Props>()

const formatYear = (dateStr: string) => {
  const date = new Date(dateStr)
  return date.getFullYear()
}

const formatMonthDay = (dateStr: string) => {
  const date = new Date(dateStr)
  return `${String(date.getMonth() + 1).padStart(2, '0')}.${String(date.getDate()).padStart(2, '0')}`
}

const getWeekday = (dateStr: string) => {
  const date = new Date(dateStr)
  const weekdays = ['周日', '周一', '周二', '周三', '周四', '周五', '周六']
  return weekdays[date.getDay()]
}

const formatFullTime = (dateStr: string) => {
  const date = new Date(dateStr)
  return date.toLocaleString('zh-CN', {
    year: 'numeric',
    month: 'long',
    day: 'numeric',
    hour: '2-digit',
    minute: '2-digit'
  })
}

const getWeatherText = (weather: string) => {
  const weatherTextMap: Record<string, string> = {
    sunny: '☀ 晴',
    cloudy: '☁ 多云',
    rainy: '☂ 雨',
    snowy: '❄ 雪'
  }
  return weatherTextMap[weather] || weather
}

const getMoodText = (mood: string) => {
  const moodTextMap: Record<string, string> = {
    happy: '愉快',
    sad: '伤感',
    neutral: '平静',
    excited: '兴奋',
    tired: '疲倦'
  }
  return moodTextMap[mood] || mood
}
</script>

<style scoped>
.vintage-journal {
  padding: 40px 20px;
  background: #f5e6d3;
  min-height: 100vh;
}

.entries-list {
  max-width: 800px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 40px;
}

.entry-page {
  background: #fefdfb;
  padding: 40px;
  position: relative;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  animation: fadeInUp 0.6s ease-out backwards;
  border: 1px solid #d4c5b0;
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(30px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* 纸张纹理 */
.paper-texture {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-image:
    repeating-linear-gradient(
      90deg,
      transparent,
      transparent 2px,
      rgba(139, 115, 85, 0.02) 2px,
      rgba(139, 115, 85, 0.02) 3px
    ),
    repeating-linear-gradient(
      0deg,
      transparent,
      transparent 2px,
      rgba(139, 115, 85, 0.02) 2px,
      rgba(139, 115, 85, 0.02) 3px
    );
  pointer-events: none;
  opacity: 0.5;
}

/* 装饰性边框 */
.decorative-border {
  position: absolute;
  top: 15px;
  left: 15px;
  right: 15px;
  bottom: 15px;
  border: 2px solid #c9a876;
  pointer-events: none;
}

.corner {
  position: absolute;
  width: 20px;
  height: 20px;
  border-color: #8b7355;
}

.corner-tl {
  top: -2px;
  left: -2px;
  border-top: 3px solid currentColor;
  border-left: 3px solid currentColor;
}

.corner-tr {
  top: -2px;
  right: -2px;
  border-top: 3px solid currentColor;
  border-right: 3px solid currentColor;
}

.corner-bl {
  bottom: -2px;
  left: -2px;
  border-bottom: 3px solid currentColor;
  border-left: 3px solid currentColor;
}

.corner-br {
  bottom: -2px;
  right: -2px;
  border-bottom: 3px solid currentColor;
  border-right: 3px solid currentColor;
}

/* 日期邮戳 */
.date-stamp {
  position: absolute;
  top: 30px;
  right: 30px;
  z-index: 1;
}

.stamp-circle {
  width: 100px;
  height: 100px;
  border: 3px solid #b8860b;
  border-radius: 50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(218, 165, 32, 0.1);
  transform: rotate(-15deg);
  font-family: 'Courier New', monospace;
  color: #8b6914;
  font-weight: bold;
  box-shadow: inset 0 0 10px rgba(184, 134, 11, 0.3);
}

.stamp-top {
  font-size: 12px;
  margin-bottom: 2px;
}

.stamp-middle {
  font-size: 20px;
  margin: 2px 0;
}

.stamp-bottom {
  font-size: 11px;
  margin-top: 2px;
}

/* 天气标签 */
.weather-label {
  position: absolute;
  top: 140px;
  right: 40px;
  background: #d4af37;
  color: white;
  padding: 6px 14px;
  border-radius: 4px;
  font-size: 13px;
  font-weight: 600;
  box-shadow: 2px 2px 6px rgba(0, 0, 0, 0.2);
  transform: rotate(5deg);
}

/* 心情贴纸 */
.mood-sticker {
  position: absolute;
  top: 180px;
  right: 35px;
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  color: white;
  box-shadow: 2px 2px 6px rgba(0, 0, 0, 0.2);
  transform: rotate(-8deg);
}

.mood-sticker.mood-happy { background: #f4a460; }
.mood-sticker.mood-sad { background: #6495ed; }
.mood-sticker.mood-neutral { background: #a9a9a9; }
.mood-sticker.mood-excited { background: #cd5c5c; }
.mood-sticker.mood-tired { background: #9370db; }

/* 内容区域 */
.content-area {
  padding-right: 140px;
  min-height: 200px;
}

.entry-title {
  font-size: 26px;
  color: #5d4037;
  margin: 0 0 20px 0;
  font-family: 'Georgia', serif;
  font-weight: 600;
  border-bottom: 2px solid #c9a876;
  padding-bottom: 10px;
  display: inline-block;
}

.entry-content {
  margin-bottom: 24px;
}

.handwriting {
  font-size: 16px;
  line-height: 2;
  color: #4a4a4a;
  font-family: 'STKaiti', 'KaiTi', serif;
  text-align: justify;
  margin: 0;
}

/* 复古标签 */
.vintage-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 20px;
}

.vintage-tag {
  background: #e8d5b7;
  color: #5d4037;
  padding: 5px 14px;
  border: 2px dashed #a67c52;
  border-radius: 4px;
  font-size: 13px;
  font-weight: 500;
  font-family: 'Georgia', serif;
}

/* 底部时间戳 */
.footer-time {
  margin-top: 30px;
  text-align: right;
  font-size: 13px;
  color: #8b7355;
  font-family: 'Georgia', serif;
  font-style: italic;
}

/* 装饰性花朵 */
.decoration-flower {
  position: absolute;
  bottom: 30px;
  left: 40px;
  font-size: 32px;
  color: #d4af37;
  opacity: 0.4;
  transform: rotate(-20deg);
}

@media (max-width: 768px) {
  .entry-page {
    padding: 30px 20px;
  }

  .content-area {
    padding-right: 0;
  }

  .date-stamp {
    position: static;
    margin-bottom: 20px;
  }

  .stamp-circle {
    transform: rotate(0);
  }

  .weather-label,
  .mood-sticker {
    position: static;
    display: inline-block;
    margin: 10px 5px;
    transform: rotate(0);
  }
}
</style>
